package com.aaa.controller.system;

import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.system.Userinfo;
import com.aaa.service.system.UserinfoService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：张恒（1371745897@qq.com）
 * @date ：Created in 2022/8/30 20:25
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/userinfo")
public class UserinfoController extends BaseController {
    @Autowired
    UserinfoService userinfoService;


    /**
     * @param pageSortEntity
     * @param userinfo
     * @return
     * @create by: 张恒
     * @description: 查询所有
     * @create time: 2022/8/31 9:56
     */
    @RequestMapping("queryAllUserinfoPage.do")
    public Result queryAllUserinfoPage(PageSortEntity pageSortEntity, Userinfo userinfo) {
        Page page = userinfoService.queryAllUserinfoPage(pageSortEntity, userinfo);
        return success(page.getResult(), page.getTotal());
    }

    /**
     * @param
     * @return
     * @create by: 张恒
     * @description: 添加
     * @create time: 2022/9/1 14:42
     */
    @RequestMapping("saveUserinfo.do")
    public Result saveUserinfo(Userinfo userinfo) {
        boolean b = userinfoService.saveUserinfo(userinfo);
        if (b) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * @param id
     * @return
     * @create by: 张恒
     * @description: 删除
     * @create time: 2022/9/1 16:12
     */
    @RequestMapping("deleteUserinfoById.do")
    public Result deleteUserinfoById(Integer[] id) {
        boolean b = userinfoService.deleteUserinfoById(id);
        if (b) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * @param userinfo
     * @return
     * @create by: 张恒
     * @description: 修改
     * @create time: 2022/9/1 18:56
     */
    @RequestMapping("updateUserinfo.do")
    public Result updateUserinfo(Userinfo userinfo) {
        boolean b = userinfoService.updateUserinfo(userinfo);
        if (b) {
            return success();
        } else {
            return fail();
        }
    }


    /**
     * @create by: 张恒
     * @description: 修改密码
     * @create time: 2022/9/13 11:00
     * @param userinfo
     * @return
     */
    @RequestMapping("updatePasswordUserinfo.do")
    public Result updatePasswordUserinfo(Userinfo userinfo){
        boolean b = userinfoService.updatePasswordUserinfo(userinfo);
        if (b) {
            return success();
        } else {
            return fail();
        }
    }


    /**
     * @param userinfo
     * @return
     * @create by: 张恒
     * @description: 题目唯一性效验
     * @create time: 2022/8/31 17:27
     */
    @GetMapping("repetitionName.do")
    public Result repetitionName(Userinfo userinfo) {
        boolean b = userinfoService.repetitionName(userinfo);
        if (b) {
            return success("用户名可用");
        } else {
            return fail("用户名重复或为空,不可用");
        }
    }
}